﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;

namespace FBEventMaker.Twitter
{
    public partial class TwitterInfo : PhoneApplicationPage
    {
        public TwitterInfo()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            WebClient twitter = new WebClient();
            twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
            twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + UserName.Text));
        }

        void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
           // throw new NotImplementedException();
            if (e.Error != null)
                return;
            XElement xmlTweets = XElement.Parse(e.Result);
            listBox1.ItemsSource = from tweet in xmlTweets.Descendants("status")
                                   select new TwitterItem
          {
              ImageSource = tweet.Element("user").Element("profile_image_url").Value,
              Message = tweet.Element("text").Value,
              Username = tweet.Element("user").Element("screen_name").Value
           
          };


        }

        public class TwitterItem
        {
            public string Username { get; set; }
            public string Message { get; set; }
            public string ImageSource { get; set; }
        }
    }
}